/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services.implementation.paypal;

import com.paypal.sdk.profiles.APIProfile;
import com.paypal.sdk.profiles.ProfileFactory;
import com.paypal.sdk.services.CallerServices;
import com.paypal.soap.api.BasicAmountType;
import com.paypal.soap.api.CurrencyCodeType;
import com.paypal.soap.api.PaymentActionCodeType;
import com.paypal.soap.api.SetExpressCheckoutRequestDetailsType;
import com.paypal.soap.api.SetExpressCheckoutRequestType;
import com.paypal.soap.api.SetExpressCheckoutResponseType;

/**
 *
 * @author smile
 */
public class ECSetExpressCheckout 
{

	public String ECSetExpressCheckoutCode(String paymentAmount, String returnURL, String cancelURL, 
										PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType)
	{
		String responseValue = null;
		// Facade class that implements API caller services
		CallerServices caller = new CallerServices();
		
		try
		{
			// Interface which defines the information PayPal needs to know about a merchant in order to provide API services. 
			APIProfile profile = ProfileFactory.createSignatureAPIProfile();
			/*
			 WARNING: Do not embed plaintext credentials in your application code.
			 Doing so is insecure and against best practices.
			 Your API credentials must be handled securely. Please consider
			 encrypting them for use in any production environment, and ensure
			 that only authorized individuals may view or modify them.
			 */
		// Set up your API credentials, PayPal end point, and API version.
			profile.setAPIUsername("Sel_01_1309787097_biz_api1.gmail.com");
			profile.setAPIPassword("1309787136");
			profile.setSignature("A3vsavgqWrm5eIuZDJ5rocMWlCRTAEXhkMekgy5oFv-JSx.a665Qj0s.");
			profile.setEnvironment("sandbox");
			caller.setAPIProfile(profile);
			
			SetExpressCheckoutRequestType pprequest = new SetExpressCheckoutRequestType();
			pprequest.setVersion("51.0");

		// Add request-specific fields to the request.
			SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();
			details.setReturnURL(returnURL);
			details.setCancelURL(cancelURL);
			BasicAmountType orderTotal = new BasicAmountType();
			orderTotal.set_value(paymentAmount);
			orderTotal.setCurrencyID(currencyCodeType);
			details.setOrderTotal(orderTotal);
			details.setPaymentAction(paymentAction);
			pprequest.setSetExpressCheckoutRequestDetails(details);

		// Execute the API operation and obtain the response.
			SetExpressCheckoutResponseType ppresponse = (SetExpressCheckoutResponseType) caller.call("SetExpressCheckout", pprequest);
			
			System.out.println(ppresponse.getCorrelationID().toString() + " -> getCorrelationID");
			System.out.println(ppresponse.getToken().toString() + " -> getToken");
			
			responseValue = ppresponse.getToken().toString();
			
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
		
		return responseValue;
		
	}
}

//
//		ECSetExpressCheckout test = new ECSetExpressCheckout();
//		ECDoExpressCheckout dsads = new ECDoExpressCheckout();
//		//ECGetExpressCheckout test2 = new ECGetExpressCheckout();
//		
//		
//		String token = test.ECSetExpressCheckoutCode("100", "http://localhost", "http://localhost", PaymentActionCodeType.Sale, CurrencyCodeType.USD);
//
//	    dsads.ECDoExpressCheckoutCode("EC-8TK35357H20302424", "8WESYCQT4THJG", "100",PaymentActionCodeType.Sale, CurrencyCodeType.USD);
